package com.warm.pump.module.sys.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.sys.bean.po.gen.SysRole;
import com.warm.pump.module.sys.mapper.gen.SysRoleMapper;
import com.warm.pump.module.sys.bean.po.gen.SysRoleExample;

@Repository
public class SysRoleDao {
    // 日志对象
    private transient Log log = LogFactory.getLog(this.getClass());
    @Autowired
    private SysRoleMapper sysRoleMapper;

    // 增加一个后台SysRole表

    public boolean insert(SysRole sysRole) {
        try {
            sysRoleMapper.insert(sysRole);
            log.debug("后台SysRole表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole表增加失败");
            throw new ServiceException("后台SysRole表增加失败", e);
        }
    }
    // 增加一个后台SysRole表Selective

    public boolean insertSelective(SysRole sysRole) {
        try {
            sysRoleMapper.insertSelective(sysRole);
            log.debug("后台SysRole表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole表增加失败");
            throw new ServiceException("后台SysRole表增加失败", e);
        }
    }

    // 删除一个后台SysRole表

    public boolean deleteByPrimaryKey(Long roleId) {
        try {
            sysRoleMapper.deleteByPrimaryKey(roleId);
            log.debug("后台SysRole表删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole表删除失败");
            throw new ServiceException("后台SysRole表删除失败", e);
        }
    }
    // 删除一个后台SysRole表byMap

    public boolean deleteByMap(Map sysRoleMap) {
        try {
            sysRoleMapper.deleteByExample(createSysRoleExample(sysRoleMap, null, null));
            log.debug("后台SysRole根据Map删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole根据GroupID删除失败");
            throw new ServiceException("后台SysRole根据object删除失败", e);
        }
    }
    // 修改一个后台SysRole表

    public boolean updateByPrimaryKey(SysRole sysRole) {
        try {
            sysRoleMapper.updateByPrimaryKey(sysRole);
            log.debug("后台SysRole表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole表修改失败");
            throw new ServiceException("后台SysRole表修改失败", e);
        }
    }
    // 修改一个后台SysRole表Selective

    public boolean updateByPrimaryKeySelective(SysRole sysRole) {
        try {
            sysRoleMapper.updateByPrimaryKeySelective(sysRole);
            log.debug("后台SysRole表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台SysRole表修改失败");
            throw new ServiceException("后台SysRole表修改失败", e);
        }
    }
    // 修改一个后台SysRole表

    public boolean updateByMap(SysRole sysRole, Map sysRoleMap) {
        try {
            sysRoleMapper.updateByExample(sysRole, createSysRoleExample(sysRoleMap, null, null));
            log.debug("后台批量SysRole表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量SysRole表修改失败");
            throw new ServiceException("后台SysRole表批量修改失败", e);
        }
    }
    // 修改一个后台SysRole表Selective

    public boolean updateByMapSelective(SysRole sysRole, Map sysRoleMap) {
        try {
            sysRoleMapper.updateByExampleSelective(sysRole, createSysRoleExample(sysRoleMap, null, null));
            log.debug("后台批量SysRole表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量SysRole表修改失败");
            throw new ServiceException("后台SysRole表批量修改失败", e);
        }
    }

    // 查询一个后台SysRole表

    public SysRole selectByPrimaryKey(Long roleId) {
        return sysRoleMapper.selectByPrimaryKey(roleId);
    }

    // 查询一个后台SysRole表-根据map

    public SysRole selectByMap(Map sysRoleMap) {
        List<SysRole> list = getListByMap(sysRoleMap);
        if (list == null || list.isEmpty()) {
            return null;
        } else {
            return list.get(0);
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 查询所有后台SysRole表

    public List<SysRole> getListByMap(Map sysRoleMap) {

        return sysRoleMapper.selectByExample(createSysRoleExample(sysRoleMap, null, null));
    }

    //统计后台SysRole表数量

    public int countTotalByMap(Map sysRoleMap) {

        return sysRoleMapper.countByExample(createSysRoleExample(sysRoleMap, null, null));
    }


    public List<SysRole> getListByMapPage(Map sysRoleMap, int limitStart,
                                          int limitOffset) {

        return sysRoleMapper.selectByExample(createSysRoleExample(sysRoleMap, limitStart, limitOffset));
    }


    public PageBean getPageBeanByMap(Map sysRoleMap, int pageNo, int pageSize) {
        Integer count = countTotalByMap(sysRoleMap);
        PageBean pageBean = new PageBean();
        pageBean.setCount(count);
        pageBean.setPageNo(pageNo);
        pageBean.setPageSize(pageSize);
        int limitStart = pageBean.getStartNo();
        int limitOffset = pageSize;
        pageBean.setData(sysRoleMapper.selectByExample(createSysRoleExample(sysRoleMap, limitStart, limitOffset)));
        return pageBean;
    }

    private SysRoleExample createSysRoleExample(Map sysRoleMap, Integer limitStart, Integer limitOffset) {
        SysRoleExample sysRoleEx = new SysRoleExample();
        SysRoleExample.Criteria c = sysRoleEx.createCriteria();
        Long roleId_null = TypeCast.getLong(sysRoleMap.get("roleId_null"));
        Long roleId_notNull = TypeCast.getLong(sysRoleMap.get("roleId_notNull"));
        Long roleId = TypeCast.getLong(sysRoleMap.get("roleId"));
        Long roleId_not = TypeCast.getLong(sysRoleMap.get("roleId_not"));
        Long roleId_greater = TypeCast.getLong(sysRoleMap.get("roleId_greater"));
        Long roleId_greaterEqual = TypeCast.getLong(sysRoleMap.get("roleId_greaterEqual"));
        Long roleId_less = TypeCast.getLong(sysRoleMap.get("roleId_less"));
        Long roleId_lessEqual = TypeCast.getLong(sysRoleMap.get("roleId_lessEqual"));
        List<Long> roleId_in = TypeCast.getLongList(sysRoleMap.get("roleId_in"));
        List<Long> roleId_notIn = TypeCast.getLongList(sysRoleMap.get("roleId_notIn"));
        Long roleId_between1 = TypeCast.getLong(sysRoleMap.get("roleId_between1"));
        Long roleId_between2 = TypeCast.getLong(sysRoleMap.get("roleId_between2"));
        Long roleId_notBetween1 = TypeCast.getLong(sysRoleMap.get("roleId_notBetween1"));
        Long roleId_notBetween2 = TypeCast.getLong(sysRoleMap.get("roleId_notBetween2"));

        if (roleId_null != null) {
            c.andRoleIdIsNull();
        }
        if (roleId_notNull != null) {
            c.andRoleIdIsNotNull();
        }
        if (roleId != null) {
            c.andRoleIdEqualTo(roleId);
        }
        if (roleId_not != null) {
            c.andRoleIdNotEqualTo(roleId_not);
        }
        if (roleId_greater != null) {
            c.andRoleIdGreaterThan(roleId_greater);
        }
        if (roleId_greaterEqual != null) {
            c.andRoleIdGreaterThanOrEqualTo(roleId_greaterEqual);
        }
        if (roleId_less != null) {
            c.andRoleIdLessThan(roleId_less);
        }
        if (roleId_lessEqual != null) {
            c.andRoleIdLessThanOrEqualTo(roleId_lessEqual);
        }
        if (roleId_in != null) {
            c.andRoleIdIn(roleId_in);
        }
        if (roleId_notIn != null) {
            c.andRoleIdNotIn(roleId_notIn);
        }
        if (roleId_between1 != null) {
            c.andRoleIdBetween(roleId_between1, roleId_between2);
        }
        if (roleId_notBetween1 != null) {
            c.andRoleIdNotBetween(roleId_notBetween1, roleId_notBetween2);
        }
        String roleName_null = TypeCast.getString(sysRoleMap.get("roleName_null"));
        String roleName_notNull = TypeCast.getString(sysRoleMap.get("roleName_notNull"));
        String roleName = TypeCast.getString(sysRoleMap.get("roleName"));
        String roleName_not = TypeCast.getString(sysRoleMap.get("roleName_not"));
        String roleName_greater = TypeCast.getString(sysRoleMap.get("roleName_greater"));
        String roleName_greaterEqual = TypeCast.getString(sysRoleMap.get("roleName_greaterEqual"));
        String roleName_less = TypeCast.getString(sysRoleMap.get("roleName_less"));
        String roleName_lessEqual = TypeCast.getString(sysRoleMap.get("roleName_lessEqual"));
        String roleName_like = TypeCast.getString(sysRoleMap.get("roleName_like"));
        String roleName_notLike = TypeCast.getString(sysRoleMap.get("roleName_notLike"));
        List<String> roleName_in = TypeCast.getStringList(sysRoleMap.get("roleName_in"));
        List<String> roleName_notIn = TypeCast.getStringList(sysRoleMap.get("roleName_notIn"));
        String roleName_between1 = TypeCast.getString(sysRoleMap.get("roleName_between1"));
        String roleName_between2 = TypeCast.getString(sysRoleMap.get("roleName_between2"));
        String roleName_notBetween1 = TypeCast.getString(sysRoleMap.get("roleName_notBetween1"));
        String roleName_notBetween2 = TypeCast.getString(sysRoleMap.get("roleName_notBetween2"));

        if (roleName_null != null) {
            c.andRoleNameIsNull();
        }
        if (roleName_notNull != null) {
            c.andRoleNameIsNotNull();
        }
        if (roleName != null) {
            c.andRoleNameEqualTo(roleName);
        }
        if (roleName_not != null) {
            c.andRoleNameNotEqualTo(roleName_not);
        }
        if (roleName_greater != null) {
            c.andRoleNameGreaterThan(roleName_greater);
        }
        if (roleName_greaterEqual != null) {
            c.andRoleNameGreaterThanOrEqualTo(roleName_greaterEqual);
        }
        if (roleName_less != null) {
            c.andRoleNameLessThan(roleName_less);
        }
        if (roleName_lessEqual != null) {
            c.andRoleNameLessThanOrEqualTo(roleName_lessEqual);
        }
        if (roleName_like != null) {
            c.andRoleNameLike(roleName_like);
        }
        if (roleName_notLike != null) {
            c.andRoleNameNotLike(roleName_notLike);
        }
        if (roleName_in != null) {
            c.andRoleNameIn(roleName_in);
        }
        if (roleName_notIn != null) {
            c.andRoleNameNotIn(roleName_notIn);
        }
        if (roleName_between1 != null) {
            c.andRoleNameBetween(roleName_between1, roleName_between2);
        }
        if (roleName_notBetween1 != null) {
            c.andRoleNameNotBetween(roleName_notBetween1, roleName_notBetween2);
        }
        String remark_null = TypeCast.getString(sysRoleMap.get("remark_null"));
        String remark_notNull = TypeCast.getString(sysRoleMap.get("remark_notNull"));
        String remark = TypeCast.getString(sysRoleMap.get("remark"));
        String remark_not = TypeCast.getString(sysRoleMap.get("remark_not"));
        String remark_greater = TypeCast.getString(sysRoleMap.get("remark_greater"));
        String remark_greaterEqual = TypeCast.getString(sysRoleMap.get("remark_greaterEqual"));
        String remark_less = TypeCast.getString(sysRoleMap.get("remark_less"));
        String remark_lessEqual = TypeCast.getString(sysRoleMap.get("remark_lessEqual"));
        String remark_like = TypeCast.getString(sysRoleMap.get("remark_like"));
        String remark_notLike = TypeCast.getString(sysRoleMap.get("remark_notLike"));
        List<String> remark_in = TypeCast.getStringList(sysRoleMap.get("remark_in"));
        List<String> remark_notIn = TypeCast.getStringList(sysRoleMap.get("remark_notIn"));
        String remark_between1 = TypeCast.getString(sysRoleMap.get("remark_between1"));
        String remark_between2 = TypeCast.getString(sysRoleMap.get("remark_between2"));
        String remark_notBetween1 = TypeCast.getString(sysRoleMap.get("remark_notBetween1"));
        String remark_notBetween2 = TypeCast.getString(sysRoleMap.get("remark_notBetween2"));

        if (remark_null != null) {
            c.andRemarkIsNull();
        }
        if (remark_notNull != null) {
            c.andRemarkIsNotNull();
        }
        if (remark != null) {
            c.andRemarkEqualTo(remark);
        }
        if (remark_not != null) {
            c.andRemarkNotEqualTo(remark_not);
        }
        if (remark_greater != null) {
            c.andRemarkGreaterThan(remark_greater);
        }
        if (remark_greaterEqual != null) {
            c.andRemarkGreaterThanOrEqualTo(remark_greaterEqual);
        }
        if (remark_less != null) {
            c.andRemarkLessThan(remark_less);
        }
        if (remark_lessEqual != null) {
            c.andRemarkLessThanOrEqualTo(remark_lessEqual);
        }
        if (remark_like != null) {
            c.andRemarkLike(remark_like);
        }
        if (remark_notLike != null) {
            c.andRemarkNotLike(remark_notLike);
        }
        if (remark_in != null) {
            c.andRemarkIn(remark_in);
        }
        if (remark_notIn != null) {
            c.andRemarkNotIn(remark_notIn);
        }
        if (remark_between1 != null) {
            c.andRemarkBetween(remark_between1, remark_between2);
        }
        if (remark_notBetween1 != null) {
            c.andRemarkNotBetween(remark_notBetween1, remark_notBetween2);
        }
        Date createTime_null = TypeCast.getDate(sysRoleMap.get("createTime_null"));
        Date createTime_notNull = TypeCast.getDate(sysRoleMap.get("createTime_notNull"));
        Date createTime = TypeCast.getDate(sysRoleMap.get("createTime"));
        Date createTime_not = TypeCast.getDate(sysRoleMap.get("createTime_not"));
        Date createTime_greater = TypeCast.getDate(sysRoleMap.get("createTime_greater"));
        Date createTime_greaterEqual = TypeCast.getDate(sysRoleMap.get("createTime_greaterEqual"));
        Date createTime_less = TypeCast.getDate(sysRoleMap.get("createTime_less"));
        Date createTime_lessEqual = TypeCast.getDate(sysRoleMap.get("createTime_lessEqual"));
        List<Date> createTime_in = TypeCast.getDateList(sysRoleMap.get("createTime_in"));
        List<Date> createTime_notIn = TypeCast.getDateList(sysRoleMap.get("createTime_notIn"));
        Date createTime_between1 = TypeCast.getDate(sysRoleMap.get("createTime_between1"));
        Date createTime_between2 = TypeCast.getDate(sysRoleMap.get("createTime_between2"));
        Date createTime_notBetween1 = TypeCast.getDate(sysRoleMap.get("createTime_notBetween1"));
        Date createTime_notBetween2 = TypeCast.getDate(sysRoleMap.get("createTime_notBetween2"));

        if (createTime_null != null) {
            c.andCreateTimeIsNull();
        }
        if (createTime_notNull != null) {
            c.andCreateTimeIsNotNull();
        }
        if (createTime != null) {
            c.andCreateTimeEqualTo(createTime);
        }
        if (createTime_not != null) {
            c.andCreateTimeNotEqualTo(createTime_not);
        }
        if (createTime_greater != null) {
            c.andCreateTimeGreaterThan(createTime_greater);
        }
        if (createTime_greaterEqual != null) {
            c.andCreateTimeGreaterThanOrEqualTo(createTime_greaterEqual);
        }
        if (createTime_less != null) {
            c.andCreateTimeLessThan(createTime_less);
        }
        if (createTime_lessEqual != null) {
            c.andCreateTimeLessThanOrEqualTo(createTime_lessEqual);
        }
        if (createTime_in != null) {
            c.andCreateTimeIn(createTime_in);
        }
        if (createTime_notIn != null) {
            c.andCreateTimeNotIn(createTime_notIn);
        }
        if (createTime_between1 != null) {
            c.andCreateTimeBetween(createTime_between1, createTime_between2);
        }
        if (createTime_notBetween1 != null) {
            c.andCreateTimeNotBetween(createTime_notBetween1, createTime_notBetween2);
        }
        if (sysRoleMap.get("orderBy") != null) {
            sysRoleEx.setOrderByClause((String) sysRoleMap.get("orderBy"));
        }
        if (limitStart != null && limitOffset != null) {
            sysRoleEx.setLimitStart(limitStart);
            sysRoleEx.setLimitOffset(limitOffset);
        }

        return sysRoleEx;
    }
}
